package GUI; //done

import java.awt.Rectangle;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import Common.Settings;
/**
 * This Class controls Catalog Management Window. 
 * @author ameer
 * @author waleed
 * @author bshara
 * @author kamil
 */
public class CatalogManagementWindow extends JFrame{
	/** The serial Version UID. */
	private static final long serialVersionUID = 1L;
	
	/** The add type Button. */
	private JButton addtypeButton = null;
	
	/** The add section Button. */
	private JButton addCategorButton = null;
	
	/** The add Type To Section Button. */
	private JButton addTypeToCategoryButton = null;
	
	/** The add Product To Type Button. */
	private JButton addProductToTypeButton = null;
	
	/** The jContent Panel. */
	private JPanel jContentPane = null;
	
	/** The category update window Button. */
	private CategoryUpdateWindow categoryupdateform = null;
	
	/** The type update window Button. */
	private TypeUpdateWindow typeupdateForm = null;
	
	/** The add product To type window Button. */
	private AddProductToTypeWindow addproducTotypeForm = null;
	
	/** The add type to category window. */
	private AddTypeToCategoryWindow addtypetocategoryForm = null;
	
	/** The Background Label. */
	private JLabel BackgroundLabel;
	
	/**
	 * Default constructor
	 */
	public CatalogManagementWindow(){
		super();
		initialize();		
	}
	
	/**
	 * This function initializes CatalogManagementWindow
	 */
	private void initialize(){
		this.setContentPane(getJContentPane());
		this.setTitle("Catalog Management");
		this.setBounds(Settings.Screen_x, Settings.Screen_y, 300, 300);
		BackgroundLabel = new JLabel("");
		BackgroundLabel.setIcon(new ImageIcon(CatalogManagementWindow.class.getResource("/Pictures/bg.png")));
		BackgroundLabel.setBounds(0, 0, 300, 300);
		this.add(BackgroundLabel);
	}
	
	/**
	 * This function initializes JContentPane
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			
			jContentPane.setLayout(null);
			jContentPane.add(getAddTypeButton() ,null);	
			jContentPane.add(getAddCategoryButton() ,null);	
			jContentPane.add(getAddTypeToCategoryButton() ,null);	
			jContentPane.add(getAddProductToTypeButton() ,null);				
		}
		return jContentPane;		
	}
	
	/**
	 * This function initializes addtypeButton	
	 */
	private JButton getAddTypeButton() {
		if (addtypeButton == null) {
			addtypeButton = new JButton();
			addtypeButton.setBounds(new Rectangle(46, 186, 200, 29));
			addtypeButton.setText("Add/Update Type");
			addtypeButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					typeupdateForm = new TypeUpdateWindow();
					setSize(450, 250);
					setTitle("Add/Update type");
					typeupdateForm.updateForm();	
					typeupdateForm.getCancelButton().addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							setTitle("Category Management");
							setBounds(Settings.Screen_x, Settings.Screen_y, 300, 200);
							typeupdateForm.restore();
							setContentPane(getJContentPane());					
						}	
					});
					setContentPane(typeupdateForm);					
				}	
			});
		}
		return addtypeButton;
	}
	
	/**
	 * This function initializes addCategorButton	
	 */
	private JButton getAddCategoryButton() {
		if (addCategorButton == null) {
			addCategorButton = new JButton();
			addCategorButton.setBounds(new Rectangle(46, 134, 200, 29));
			addCategorButton.setText("Add/Update Category");
			addCategorButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					categoryupdateform = new CategoryUpdateWindow();
					setSize(450, 250);
					setTitle("Add/Update section");
					categoryupdateform.updateForm();
					categoryupdateform.getCancelButton().addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							setTitle("Category Management");
							setBounds(Settings.Screen_x, Settings.Screen_y, 300, 200);
							categoryupdateform.restore();
							setContentPane(getJContentPane());					
						}	
					});
					setContentPane(categoryupdateform);					
				}	
			});
		}
		return addCategorButton;
	}
	
	/**
	 * This function initializes addTypeToCategoryButton	
	 */
	private JButton getAddTypeToCategoryButton() {
		if (addTypeToCategoryButton == null) {
			addTypeToCategoryButton = new JButton();
			addTypeToCategoryButton.setBounds(new Rectangle(46, 83, 200, 29));
			addTypeToCategoryButton.setText("Add Type to Category");
			addTypeToCategoryButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					addtypetocategoryForm = new AddTypeToCategoryWindow();
					setSize(450, 250);
					setTitle("Add type to section");
					addtypetocategoryForm.updateForm();
					addtypetocategoryForm.getCancelButton().addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							setTitle("Category Management");
							setBounds(Settings.Screen_x, Settings.Screen_y, 300, 200);
							addtypetocategoryForm.restore();
							setContentPane(getJContentPane());					
						}	
					});
					setContentPane(addtypetocategoryForm);						
				}	
			});
		}
		return addTypeToCategoryButton;
	}
	
	/**
	 * This function initializes addProductToTypeButton	
	 */
	private JButton getAddProductToTypeButton() {
		if (addProductToTypeButton == null) {
			addProductToTypeButton = new JButton();
			addProductToTypeButton.setBounds(new Rectangle(46, 32, 200, 29));
			addProductToTypeButton.setText("Add product to Type");
			addProductToTypeButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					addproducTotypeForm = new AddProductToTypeWindow();
					setSize(600, 250);
					setTitle("Add/Remove product to type");
					addproducTotypeForm.updateForm();
					addproducTotypeForm.getCancelButton().addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							setTitle("Category Management");
							setBounds(Settings.Screen_x, Settings.Screen_y, 300, 200);
							addproducTotypeForm.restore();
							setContentPane(getJContentPane());					
						}	
					});
					setContentPane(addproducTotypeForm);										
				}	
			});
		}
		return addProductToTypeButton;
	}
}
